#include "dag.h"
#include "dag_operators.h"

#include <memory>
#include <string>

using namespace dag;
using namespace std;


AddOp::AddOp(const Frame& offset)
:	m_Offset(offset)
{
}

AddOp::~AddOp() throw() {
}

auto_ptr<FrameOperator> AddOp::inflate(istream& bStream) {
	Frame frame = FrameSpec();
	frame.load(bStream);
	return auto_ptr<FrameOperator>(new AddOp(frame));
}
void AddOp::operate(const Frame& input, Frame& output) {
	if (static_cast<const FrameSpec&>(input) != 
		static_cast<const FrameSpec&>(m_Offset)) {
		throw UnequalFrameSpec(input, m_Offset);
	}
	
	output = input;
	for (size_t i = 0; i < m_Offset.bSize; i++) {
		output.bools[i] = output.bools[i] || m_Offset.bools[i];
	}
	for (size_t i = 0; i < m_Offset.iSize; i++) {
		output.ints[i] += m_Offset.ints[i];
	}
	for (size_t i = 0; i < m_Offset.fSize; i++) {
		output.floats[i] += m_Offset.floats[i];
	}
	for (size_t i = 0; i < m_Offset.dSize; i++) {
		output.doubles[i] += m_Offset.doubles[i];
	}
}
	

const string& AddOp::_frameOperatorID() const {
	return OpId::add_op;
}

void AddOp::_serialize(ostream& binaryStream) const {
	m_Offset.serialize(binaryStream);
}
	